#!/bin/bash

#
# This script calls the extract_apk.sh script many times in parallel
# for each of the sorted applications to unpack apk files and parse
# their contents.
#

original_dir=$(pwd)
for dir in malicious_apk benign_apk; do
  echo "Entering $dir"
  cd $dir
  cpus=$(ls -d /sys/devices/system/cpu/cpu[[:digit:]]* | wc -w)
  cpus=$(expr $cpus - 2)
  find `pwd` -type f -name "*.apk" | xargs --max-args=1 --max-procs=$cpus ../extract_apk.sh
  cat valid_apks.txt | sort | uniq > valid_apks.txt
  cat malformed_xml.txt | sort | uniq > malformed_xml.txt
  cat malformed_dex.txt | sort | uniq > malformed_dex.txt
  cd $original_dir
done
